package javase.ch05.homeWork.Demo3;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Threadpool {
    private ThreadPoolExecutor pool;
    public Threadpool(int maxPoolSize, int queueSize){
        pool = new ThreadPoolExecutor(
                3,  //核心线程数
                maxPoolSize,     //最大线程数
                60,       //空闲时间
                TimeUnit.SECONDS, //时间单位
                new ArrayBlockingQueue<>(queueSize) //任务队列（增加队列大小）
        );
    }

    public void execute(Runnable task){
        pool.submit(task);
    }
}
